-- This turns on checks for common mistakes that can save you a
-- lot of time debugging. It takes some processor time, so it's
-- a good idea to turn this off when you're ready to release your app.
STRICT = true

-- This turns on the debug console, which can be brought up at
-- any point by pressing the Tab key. From the console, you can
-- watch values and run any Lua statement. The console also appears
-- automatically if your app crashes. Finally, you can press
-- Control-Alt-R (Control-Option-R on a Mac) to instantly reload your
-- code from on disk. Just like STRICT, you'd want to turn this off
-- for release.
DEBUG = true

require 'zoetrope'

-- constants

-- Constant: JUMPING
-- Motion constant corresponding to jumping.
JUMPING = 'jumping'

-- Constant: WALKING
-- Motion constant corresponding to walking.
WALKING = 'walking'

-- Constant: STOPPED
-- Motion constant corresponding to stopped.
STOPPED = 'walking'





bg = love.graphics.newImage( 'background.PNG' );


-- can just be a sprite?
Cursor = Sprite:extend
{
	width = 48,
	height = 48,

	image = love.graphics.newImage('cursor.png'),

	new = function (self, obj)
		obj = obj or {}
		self:extend(obj)

		if obj.onNew then obj:onNew() end
		return obj
	end,

	onUpdate = function (self)


		-- Boundary (horizontal)

		if self.x < 0 then
			self.x = 0
		elseif self.x > 800 - 48 then
			self.x = 800 - 48
		end

		-- Boundary (horizontal)
		if self.y < 0 then
			self.y = 0
		elseif self.y > 600 - 48 then
			self.y = 600 - 48
		end


		if the.keys:pressed("left") then
			self:goLeft()
		elseif the.keys:pressed("right") then
			self:goRight()
		end

		if the.keys:pressed("up") then
			self:goUp()
		elseif the.keys:pressed("down") then
			self:goDown()
		end
	end,


	goLeft = function (self)
		self.x = self.x - 10
	end,

	goRight = function (self)
		self.x = self.x + 10
	end,


	goUp = function (self)
		self.y = self.y - 10
	end,


	goDown = function (self)
		self.y = self.y + 10
	end,

	draw = function (self, x, y)
		love.graphics.draw(self.image, x, y)
		Sprite.draw(self, x, y)
	end,
}


Whip = Sprite:extend
{
	whipcrack = false,

	draw = function ( self, x, y )
		if self.whipcrack == true then
			print("ohio")
			love.graphics.setColor(255, 0, 0)
			love.graphics.line(400, 600, the.app.cursor.x + 24, the.app.cursor.y + 24)
			love.graphics.reset()
		end
		self.whipcrack = false
		Sprite.draw(self, x, y)
	end,


}

the.app = App:new
{
	onRun = function (self)
		self:add(Tile:new{ image = 'background.png' })
		self.cursor = Cursor:new({ x = 320, y = 320 })
		self:add(self.cursor)
		self.whip = Whip:new()
		self:add(self.whip)
	end,

	onUpdate = function (self)
		if the.keys:pressed(" ") then
			self.whip.whipcrack = true
		end
    end,
}

